package com.tinusgraglin.enclusiv.ui.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.tinusgraglin.enclusiv.Util
import com.tinusgraglin.enclusiv.datalayer.repos.ArticleRepo
import com.tinusgraglin.enclusiv.datalayer.EditedArticle
import com.tinusgraglin.enclusiv.datalayer.repos.UserRepo

class NewArticleViewModel(
    val userRepo: UserRepo,
    val articleRepo: ArticleRepo
) : ViewModel() {
    val loggedInUserProfile by lazy {
        userRepo.cachedLoggedInUserProfile!!
    }

    fun upload(title: String, content: String, images: List<Long>) =
        Util.requestWithDeferredResultAsync(viewModelScope) {
            articleRepo.postArticle(EditedArticle(loggedInUserProfile.id, title, content, images))
        }
}